﻿using System;
using System.Collections.Generic;
using System.Text;
using XiaoGang.Soft.XGWMS.COM;
using XiaoGang.Soft.XGWMS.MODEL;
using System.Data.SqlClient;
using System.Data;

namespace XiaoGang.Soft.XGWMS.DAL_SQL
{
    public class DAL_M012_STORAGESCAN
    {
        /// <summary>
        /// <p><b>方法名称</b>SearchProcess</p>	
        /// <p><b>概要説明  :</b>库存信息的查询</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <param type="class" name="model">检索条件</param>
        /// <returns type = "ReturnValue">检索结果表</returns>
        public ReturnValue SearchProcess(MOD_M012_STORAGESCAN model)
        {
            StringBuilder strSql = new StringBuilder();
            if (0 != model.GOODS_NAME.Trim().Length)
            {
                strSql.AppendFormat(" AND M007.[GOODS_NM1] like '%{0}%' {1}", model.GOODS_NAME, (char)13);
            }
            if (0 != model.GOODS_GROUP_ID.Trim().Length)
            {
                strSql.AppendFormat(" AND M007.[GOODS_GROUP] = '{0}' {1}", model.GOODS_GROUP_ID, (char)13);
            }
            if (0 != model.StoreRoom_ID.Trim().Length)
            {
                //strSql.AppendFormat("   AND   [M009_STORAGE].[STOREROOM_ID] = '{0}'    {1}", model.StoreRoom_ID, (char)13);
            }
            return XGWMS.DBUtility.SqlHelper.Query(DAL_M012_STORAGESCAN_SQL.SearchStorage.Replace("@@@",strSql.ToString()));
        }

        /// <summary>
        /// 取得销售分析数据
        /// </summary>
        /// <param name="BusinessTimeStart">业务开始时间</param>
        /// <param name="BusinessTimeEnd">业务结束时间</param>
        /// <param name="OrderByType">分析类型 1:销售额 2：销售量</param>
        /// <param name="OrderByDirection">排序类型 1:由大到小 2:由小到大</param>
        /// <returns></returns>
        public ReturnValue GetAnalysis(string BusinessTimeStart,string BusinessTimeEnd,int OrderByType, int OrderByDirection)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@BusinessTimeStart", SqlDbType.VarChar,8),
                new SqlParameter("@BusinessTimeEnd", SqlDbType.VarChar,8)};
            parameters[0].Value = BusinessTimeStart;
            parameters[1].Value = BusinessTimeEnd;

            StringBuilder strSql = new StringBuilder();
            if (OrderByType==1)
            {
                strSql.AppendFormat(" Sales ");
            }
            else if (OrderByType == 2)
            {
                strSql.AppendFormat(" SalesTotal ");
            }

            if (OrderByDirection==1)
            {
                strSql.AppendFormat(" DESC ");
            }
            else if (OrderByDirection == 2)
            {
                strSql.AppendFormat(" ASC ");
            }
            return XGWMS.DBUtility.SqlHelper.Query(DAL_M012_STORAGESCAN_SQL.GetAnalysisData.Replace("@@@", strSql.ToString()),parameters);
        }
    }
}
